package com.fanghuaiming.ml.order.controller;

import com.fanghuaiming.ml.common.model.enumeration.OrderTransactionEnum;
import com.fanghuaiming.ml.order.controller.model.MessageListOrderDTO;
import com.fanghuaiming.ml.order.service.MessageListOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/****
 * @description: 订单服务接口
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2020/11/27 下午2:00
 *
 */
@RestController("order")
@RequestMapping("/order")
@Slf4j
public class OrderController {

    /**
     * 账户服务
     */
    @Autowired
    private MessageListOrderService messageListOrderService;

    /**
     * @Description: 处理订单
     *
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/12/4 下午2:56
     * @version:1.0.0
     */
    @PostMapping("/dealOrder")
    public OrderTransactionEnum dealOrder(@RequestBody MessageListOrderDTO messageListOrderDTO){
        log.info("====== 请求订单服务开始,订单号:{} ======",messageListOrderDTO.getOrderId());
        try {
            OrderTransactionEnum orderTransactionEnum = messageListOrderService.dealOrder(messageListOrderDTO);
            log.info("====== 请求订单服务成功 ======");
            return  orderTransactionEnum;
        }catch (Exception e){
            log.info("====== 请求订单服务失败 ======");
            return  OrderTransactionEnum.ERROR;
        }

    }

}
